#include "Graphics.h"

Graphics::Graphics()
{
	rotator = 0;
	env_bmps.push_back(al_load_bitmap("stonefloor.tga"));
	Animations.push_back(al_load_bitmap("rustlewalk1.tga"));
	Animations.push_back(al_load_bitmap("rustlejump1.tga"));
	Animations.push_back(al_load_bitmap("millhousewalk1.tga"));
	Animations.push_back(al_load_bitmap("millhousejump1.tga"));
	Animations.push_back(al_load_bitmap("dolanwalk1.tga"));
	Animations.push_back(al_load_bitmap("dolanjump1.tga"));
	Animations.push_back(al_load_bitmap("pedowalk1.tga"));
	Animations.push_back(al_load_bitmap("pedojump1.tga"));
	Animations.push_back(al_load_bitmap("starecatwalk2.tga"));
	Animations.push_back(al_load_bitmap("starecatjump2.tga"));
	Animations.push_back(al_load_bitmap("hitlerwalk2.tga"));
	Animations.push_back(al_load_bitmap("hitlerjump1.tga"));
	Animations.push_back(al_load_bitmap("trollwalk1.tga"));
	Animations.push_back(al_load_bitmap("trolljump1.tga"));
	Animations.push_back(al_load_bitmap("inglipwalk1.tga"));
	Animations.push_back(al_load_bitmap("inglipjump1.tga"));
	Animations.push_back(al_load_bitmap("ronpaulwalk1.tga"));
	Animations.push_back(al_load_bitmap("ronpauljump1.tga"));
	Backgrounds.push_back(al_load_bitmap("longcat-8.tga"));
	Objects.push_back(al_load_bitmap("pic1.png"));
	Objects.push_back(al_load_bitmap("cloud.png"));
	for(int i=0;i<Animations.size();i++)
	{
		al_convert_mask_to_alpha(Animations[i],al_map_rgb(255,0,255));
	}
}

ALLEGRO_BITMAP * Graphics::get_bmp(int set, int value)
{
	if(set == 0)
	{
		if(value < Animations.size())
		{
			return Animations[value+ rotator];
		}
	}
	else if(set == 1)
	{
		if(value < env_bmps.size())
		{
			return env_bmps[value];
		}
	}
	else if(set == 2)
	{
		if(value < Backgrounds.size())
		{
			return Backgrounds[value];
		}
	}
	else if(set == 3)
	{
		if(value < Objects.size())
		{
			return Objects[value];
		}
	}
}

void Graphics::rotate()
{
	rotator += 2;
	if(rotator > (Animations.size())/2 + 7)
	{
		rotator = 0;
	}
}

Graphics::~Graphics()
{
	for(int i=0;i< env_bmps.size();i++)
	{
		al_destroy_bitmap(env_bmps[i]);
	}
	for(int i=0;i< Animations.size();i++)
	{
		al_destroy_bitmap(Animations[i]);
	}
	for(int i=0;i< Backgrounds.size();i++)
	{
		al_destroy_bitmap(Backgrounds[i]);
	}
	for(int i=0;i< Objects.size();i++)
	{
		al_destroy_bitmap(Objects[i]);
	}
}